package com.bw.module_service.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bw.module_service.R
import com.bw.module_service.model.CardItem

class CardAdapter(private val cardlist:List<CardItem>):RecyclerView.Adapter<CardAdapter.CardViewHolder>() {
    class CardViewHolder(view:View):RecyclerView.ViewHolder(view){
        val iconImageView=view.findViewById<ImageView>(R.id.icon)
        val titleTextView=view.findViewById<TextView>(R.id.title)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CardViewHolder {
        val view=LayoutInflater.from(parent.context).inflate(R.layout.card_layout,parent,false)
        return CardViewHolder(view)
    }

    override fun getItemCount(): Int {
        return cardlist.size
    }

    override fun onBindViewHolder(holder: CardViewHolder, position: Int) {
       val catdItem=cardlist[position]
        holder.iconImageView.setImageResource(catdItem.icon)
        holder.titleTextView.text=catdItem.title
    }
}